在Windows 7中为我们的自定义文件类型编写自定义属性Handler.我已经安装了Windows 7 SDK并构建了示例属性处理程序.注册处理程序后,它在Windows资源管理器中运行良好,但在公共文件打开对话框中,不会显示自定义值.有没有人知道我需要做些什么特别的事情来让属性出现在常见的对话框中?
资源管理器:

文件打开对话框:

我创建了自己的自定义微调器,我可以在它实现的"自定义和库视图"中访问它View.但是,问题是当从我的调色板中拖动我的自定义微调器以在我的中使用它时main.xml,它会抛出"未处理的事件循环异常".我不知道我的错误在哪里.
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pref="http://schemas.android.com/apk/res/com.myspinner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.myspinner.Myspinner
android:id="@+id/myspinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
pref:MyEntries="@array/testarray" />
Run Code Online (Sandbox Code Playgroud)
MySpinnerattributes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MySpinner">
<attr name="MyEntries" format="reference"/>
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)
spinnerlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="@string/large_text" android:gravity="center"/>
Run Code Online (Sandbox Code Playgroud)
Myspinner.java
public class Myspinner extends Spinner{
LayoutInflater inflater;
CharSequence cs[]={"MySpinner"};
String s[]={"MySpinner"};
View row;
TextView txt;
public Myspinner(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setAttributes(attrs);
this.setAdapter(new MyAdapter(this.getContext(), R.layout.spinnerlayout,s));
}
public Myspinner(Context …Run Code Online (Sandbox Code Playgroud) android custom-attributes custom-component android-arrayadapter android-spinner
如何强制子类实现其超类的某些属性?原因是我想使用属性来获取有关类的一般信息,例如"DisplayName","Description"或"Capabilities".
所以我想我可以在超类中实现它们并强制子类来实现属性.
是否有abstract类似于方法的属性?
[abstract DeclareMe]
public abstract class InheritMe {
public abstract void DeclareMe();
}
Run Code Online (Sandbox Code Playgroud) 我不打算实现Java"throws"关键字.有关throws关键字的优点及其未在C#中实现的原因的讨论,请参见http://www.artima.com/intv/handcuffsP.html.
但是,如果有办法创建如下所示的属性,我很好奇:
[ThrowsException( exceptionType = NullReferenceException )]
[ThrowsException( exceptionType = AuthenticationException )]
public void Login( Credentials credz )
{
// ... etc...
}
Run Code Online (Sandbox Code Playgroud)
这样 - 当调用一个用一个或多个ThrowsException属性修饰的方法时,所述方法抛出的异常类型(至少是由ThrowsException属性显式声明的异常)将在方法的文档中可见
这与Java"throws"关键字不同,因为它不需要调用者处理这些异常.这样做可能会引入重大更改,例如,在不处理版本更改引入的新异常的客户端应用程序中.
虽然可以使用:
/// <exception cref="member">description</exception>
Run Code Online (Sandbox Code Playgroud)
我使用属性的意图是,如果异常的名称已更改或异常不再存在,则项目不会编译.因此,如何记录引发异常,不是同一个问题.
更新:2013-05-23
我已经想出了一种通过使用属性而不使用插件来解决问题的方法.我将在本周末尝试解决这个问题,如果能按预期工作,我将很乐意发布解决方案.如果有人打我发布解决方案,我很乐意接受他们的回答.
因为直到星期一我都无法解决这个问题,如果你能打败我,我会提供赏金 - 一个可以接受的答案是:
我认为XML文档不能从ThrowsException属性反映异常,直到项目构建完成之后.
看到一个基于Resharper的解决方案(因为它在我工作的大多数开发工厂中都很常见)会很有趣,但是如果有一个解决方案仍然与第三方工具无关,那么它将不被接受.类似地,只能在Visual Studio中使用的解决方案可以通过依赖于Resharper的解决方案来接受,但如果有一个解决方案可以在其他IDE中工作,例如MonoDevelop(支持更多框架 - 甚至更好),则不会接受它.
我想,以确保两个接口都从不在编译时相同的类,类似于如何发现AttributeUsage检查定制在编译时属性.
例如:
[InterfaceUsage(MutuallyExclusive = typeof(B))]
interface A {
//...
}
interface B {
//...
}
class C : A, B { //should throw an error on compile time
//...
}
Run Code Online (Sandbox Code Playgroud)
我显然可以在运行时使用反射来完成此操作,但我对编译时解决方案很感兴趣.
我想象一个可能不存在开箱即用 - 但有没有办法创建一个在编译时运行的自定义属性,就像AttributeUsage一样?
我有一堆路由,我希望能够在我的Web.Config文件中抛出.我需要为集合中的每个部分/项目添加一个键和两个值字段.有点像这样......
<routes>
<add
key="AdministrationDefault"
url="Administration/"
file="~Administration/Default.aspx" />
<add
key="AdministrationCreateCampaign"
url="Administration/CreateCampaign/"
file="~/Administration/CreateCampaign.aspx" />
<add
key="AdministrationLogout"
url="Administration/Leave/"
file="~/Administration/Leave.aspx" />
</routes>
Run Code Online (Sandbox Code Playgroud)
这可能吗?
有人知道任何代码重复DebuggerDisplayAttribute分析和收集结果字符串的方式吗?
我想创建一个几乎完成示例事务的自定义属性.类似于"当遇到断点时...",您可以在花括号中使用变量,如"{variable}"中所示.
我已经处理过简单的情况,例如"{Name}",但像"{Foo.Name}"这样的东西需要我需要帮助的额外反射代码.
基本上,我想使用DebuggerDisplayAttribute文档中定义的规则解析字符串.目前,我可以解析并解决"我是{GetName()}".我需要帮助"Foo的名字:{Foo.Name}"
我正在尝试编写一个方法,在具有特定自定义属性的程序集中查找所有类型.我还需要能够提供匹配的字符串值.需要注意的是,我希望能够在任何类上运行它并返回任何值.
例如:我想执行这样的调用
Type tTest = TypeFinder.GetTypesWithAttributeValue(Assembly.Load("MyAssembly"), typeof(DiagnosticTestAttribute), "TestName", "EmailTest");
Run Code Online (Sandbox Code Playgroud)
到目前为止我的方法看起来像这样:
public static Type GetTypesWithAttributeValue(Assembly aAssembly, Type tAttribute, string sPropertyName, object oValue)
{
object oReturn = null;
foreach (Type type in aAssembly.GetTypes())
{
foreach (object oTemp in type.GetCustomAttributes(tAttribute, true))
{
//if the attribute we are looking for matches
//the value we are looking for, return the current type.
}
}
return typeof(string); //otherwise return a string type
}
Run Code Online (Sandbox Code Playgroud)
我的属性看起来像这样:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
public class DiagnosticTestAttribute : Attribute
{
private string _sTestName …Run Code Online (Sandbox Code Playgroud) 如果使用其他属性,我想强制使用属性.如果将特殊的第三方属性附加到属性,则还需要将此属性赋予属性是否有可能这样做?
例如:
[Some3rdPartyAttribute("...")]
[RequiredAttribute("...)]
public bool Example{get; set;}
Run Code Online (Sandbox Code Playgroud)
应该没有编译错误,
[Some3rdPartyAttribute("...")]
public bool Example{get; set;}
Run Code Online (Sandbox Code Playgroud)
应该带来编译错误或警告.
该属性本身的定义类似于http://msdn.microsoft.com/en-US/library/z919e8tw(v=vs.80).aspx本身的示例.但是如果使用另一个属性,如何强制使用属性?
我正在玩Aurelia中的自定义元素功能,并试图创建一个'进度条'元素.
进步,bar.js
import {customElement, bindable} from 'aurelia-framework';
@customElement('progress-bar')
export class ProgressBar
{
//do stuff//
}
Run Code Online (Sandbox Code Playgroud)
进步,一个bar.html
<template>
<link rel="stylesheet" type="text/css" href="src/components/progress-bar.css">
<div class='progress-bar' tabindex=0 ref="bar">bloo</div>
</template>
Run Code Online (Sandbox Code Playgroud)
test.html(相关部分)
<require from="./components/progress-bar"></require>
<progress-bar ref="pb">a</progress-bar>
Run Code Online (Sandbox Code Playgroud)
所有这一切都很好.但我正在努力如何让主页可以调用某个函数或更改元素上的某些属性,这应该在进度条本身上做一些事情.
我试图在progress-bar.js中创建一个函数'doSomething',但是我无法在test.js中访问它.
添加到progress-bar.js
doSomething(percent, value) {
$(this.bar).animate('width: ${percent}%', speed);
}
Run Code Online (Sandbox Code Playgroud)
在test.js里面
clicked() {
console.log(this.pb); // this returns the progress bar element fine
console.log(this.pb.doSomething); //this returns as undefined
this.pb.doSomething(percent, value); // this fails outright with error: typeError - doSomething is not a function
}
Run Code Online (Sandbox Code Playgroud)
接下来,我尝试在progress-bar元素中设置自定义属性,并可能使用valueChange来改变div.
里面的进度bar.js
@bindable percent=null;
@bindable speed=null; …Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×1
android ×1
attributes ×1
aurelia ×1
compile-time ×1
exception ×1
inheritance ×1
javascript ×1
reflection ×1
shell ×1
web-config ×1
windows-7 ×1