我正在尝试在XSD中定义一个元素类型,我想要一个可选属性,如果存在,可以包含一个浮点数,或者为空(但仍然存在).
即:
<xs:element name="MyElement">
<xs:complexType>
<xs:attribute name="optionalFloatAttribute" type="xs:float" use="optional"/>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
需要"修复"以允许以下所有xml: -
<MyElement/>
or
<MyElement optionalFloatAttribute=""/>
or
<MyElement optionalFloatAttribute="3.14159"/>
Run Code Online (Sandbox Code Playgroud)
我能看到这样做的唯一方法是将类型更改为xs:string,并使用xs:restriction正则表达式.但这对我来说似乎并不理想.有没有更好的办法?
而且我必须能够支持xml的这些变体 - 程序和现有的xml是遗留的,我试图反向创建一个模式,以匹配我在我们必须视为有效的xml时看到的无数变体.
背景:我试图在创建虚拟数据时获得一些随机的"十六进制"值,并提出了这种结构:
SELECT TOP 100
result = (CASE ABS(Binary_Checksum(NewID())) % 16
WHEN -1 THEN 'hello'
WHEN 0 THEN '0'
WHEN 1 THEN '1'
WHEN 2 THEN '2'
WHEN 3 THEN '3'
WHEN 4 THEN '4'
WHEN 5 THEN '5'
WHEN 6 THEN '6'
WHEN 7 THEN '7'
WHEN 8 THEN '8'
WHEN 9 THEN '9'
WHEN 10 THEN 'a'
WHEN 11 THEN 'b'
WHEN 12 THEN 'c'
WHEN 13 THEN 'd'
WHEN 14 THEN 'e'
WHEN 15 THEN 'f'
ELSE 'huh' …Run Code Online (Sandbox Code Playgroud) 在OpenGL ES 2.0的介绍中,可以在这里找到:http://www.webreference.com/programming/opengl_es/2.html 定义了一个顶点着色器:
GLbyte vShaderStr[] =
"attribute vec4 vPosition; \n"
"void main() \n"
"{ \n"
" gl_Position = vPosition; \n"
"}; \n";
Run Code Online (Sandbox Code Playgroud)
vPosition属性是一个四分量向量.
稍后在文本中,应用程序将与片段着色器一起编译顶点着色器.使用glBindAttribLocation建立一个句柄,将应用程序顶点数据传递给着色器:
// Bind vPosition to attribute 0
glBindAttribLocation(programObject, 0, "vPosition");
Run Code Online (Sandbox Code Playgroud)
现在链接了两个着色器,程序已准备就绪.
用例是这样的:
GLfloat vVertices[] = {0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f};
...
// Load the vertex data
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
Run Code Online (Sandbox Code Playgroud)
意思是:
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices) :将顶点数据传递给程序,使用位置0,每个顶点有3个组件,类型为float,不使用规范化.
glEnableVertexAttribArray(0) :着色器将使用传递的数据.
glDrawArrays(GL_TRIANGLES, 0, 3); …
我有数百个由DataSync自动生成的程序.
我没有时间和感觉手动删除它们.
他们都从一开始 DataSync.
有没有办法删除名称以DataSync.?开头的所有存储过程?
我一直在学习这个MembershipProvider类,我认为该Membership.ValidateUser()方法应该用于记录用户.
但是,我刚刚得知有一个FormsAuthentication.Authenticate().
ValidateUser()内在的目的是Membership什么?
我在尝试进行npm安装时收到此错误...我已经被这个问题困扰了4天...请有人帮助我...
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "c:\\Program Files\\nodejs\\node.exe" "c:\\Users\\Username\\AppData\\Roaming\\npm\\node_modules\\n pm\\bin\\npm-cli.js" "install"
npm ERR! node v0.10.33
npm ERR! npm v2.1.5
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! phantomjs@1.9.12 install: `node install.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the phantomjs@1.9.12 install script.
npm ERR! This is most likely a problem with the phantomjs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on …Run Code Online (Sandbox Code Playgroud) 继这个关于在Visual Studio 2015中使用不同Visual Basic版本的问题之后,我将在Visual Basic 14中运行新的语言功能,如此处和此处所述.
其中之一是能够在结构中使用无参数构造函数,如下所示:
Structure MyStruct1
Public f As Integer
Sub New()
f = 15
End Sub
End Structure
Run Code Online (Sandbox Code Playgroud)
当我在Visual Studio 2015中的代码中尝试此操作时,我仍然会在以下情况下出现红色错误波形New():
BC30629结构不能声明没有参数的非共享"Sub New".
我还没有看到任何说明在发布之前被拉掉的地方.
我误解了这个新功能的作用吗?
我的大脑现在累了,不能想出一个简单的解决方案.
var res = error.Split('|');
return String.Format("Name: {0} <br /> Email: {1}", res[0] , res[1]);
Run Code Online (Sandbox Code Playgroud)
如果没有| 然后它抛出一个错误,这将是一个快速和优雅的方式来只是抛出一个默认的"无名称"或传递它.我只关心位置[0]和[1].
样本数据
Tom | huntard@123.com
Tom
Tom | huntard@123.com
Tom | huntard@123.com | texas
Run Code Online (Sandbox Code Playgroud)
我需要一个redbull.
我有一些代码生成表达式作为数据库读取中的"where"语句传递,我正在尝试加快速度.
下面的示例使where语句与传入值的表的PK相匹配:
private Expression MakeWhereForPK(int id)
{
var paramExp = Expression.Parameter(typeof(Brand),"b");
//Expression to get value from the entity
var leftExp = Expression.Property(paramExp,"ID");
//Expression to state the value to match (from the passed in variable)
var rightExp = Expression.Constant(id,typeof(int));
//Expression to compare the two
var whereExp = Expression.Equal(leftExp,rightExp);
return Expression.Lambda<Func<Brand,bool>>(whereExp,paramExp);
}
Run Code Online (Sandbox Code Playgroud)
以上是对问题的简化 - 真实的东西包括使表格查询并找到其PK等的代码.它实际上是通常在代码中执行相同的操作:
ctx.Brands.Where(b => b.ID = id);
Run Code Online (Sandbox Code Playgroud)
这样做没问题,但是,在进行测试以优化某些事情时,我发现它相当慢 - 做上述1000000次需要大约25秒.如果我省略上面的最后一行(但很明显它没用!),它会更好,所以看起来像Expression.Lamba需要大约2/3的时间,但其余的也不是很好.
如果所有的查询都会立即发生,我可以把它变成一个IN样式表达式并生成一次,但遗憾的是这是不可能的,所以我希望的是保存上面的大多数代,并只重用生成的表达式,但传递不同的值id.
请注意,由于这将传递给Linq,我无法编译表达式以获得可以在调用时传入的整数参数 - 它必须保留为表达式树.
因此,以下可能是一个简单的版本,用于进行计时练习:
Expression<Func<Brand,bool>> savedExp;
private Expression MakeWhereForPKWithCache(int id)
{
if (savedExp == …Run Code Online (Sandbox Code Playgroud) 假设我想要一个Box可以包含内部内容的泛型类,所以它是一个Box<T>.Box<T>有一个Transform方法返回一个Box<U>:
public Box<U> Transform<U>(Func<T, U> transform)
Run Code Online (Sandbox Code Playgroud)
到目前为止,这很简单.但是,我实际上需要一个摘要Box,因为值被加框和转换的方式是特定于实现的.(我没有接口,因为有其他方法是通过抽象方法的组合实现的,但这并不会改变任何东西).
当然,我希望我的重写Transform方法返回一个合适的子类Box,而不是Box它自己.由于覆盖方法的返回类型在C#中是不变的,我转向奇怪的重复模板模式(请参阅参考资料IComparable<T>):
public abstract class Box<B, T> where B : Box<B, T>
Run Code Online (Sandbox Code Playgroud)
现在我继承的每一个课都Box<B, T>应该引用自己或者所有地狱都是松散的:
public class FooBox<T> : Box<FooBox, T>
Run Code Online (Sandbox Code Playgroud)
但是,这完全破坏了这个Transform方法:
public abstract Box<B, U> Transform<U>(Func<T, U> transform);
Run Code Online (Sandbox Code Playgroud)
无法编译The type 'B' cannot be used as type parameter 'B' in the generic type or method 'Test.Box<B,T>'. There …